package bman.filecopy;

import java.io.File;
import java.io.IOException;

public class Session
{
	File pwd = new File(".");
	String id = "";
	
	public Session(String id)
	{
		this.id = id;
	}
	
	public boolean cd(String dir)
	{
		File nf = new File(pwd.getAbsolutePath()+File.separator+dir);
		System.out.println("cd "+nf.getAbsolutePath());
		if(nf.exists() && nf.isDirectory())
		{
			pwd = nf;
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public String ls()
	{
		String[] s = pwd.list();
		
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<s.length;i++)
		{
			sb.append(s[i]+"\n");
		}
		
		return sb.toString();
	}
	
	public String pwd()
	{
		try
		{
			return pwd.getCanonicalPath();
		}
		catch (IOException e)
		{
			e.printStackTrace();
			return e.toString();
		}
	}
}
